package Practice9_MethodReference.p2;

import Utils.delegations.func.IProducerWithParams;
import org.junit.jupiter.api.Test;

public class P1 {
    public void method1(int num, Calcable calcable) {
        System.out.println(calcable.calc(num));
    }

    public void method2(int num, IProducerWithParams<Integer> producer) {
        System.out.println(producer.invoke(num));
    }

    public Math method3(String name, IProducerWithParams<Math> producer) {
        return producer.invoke(name);
    }

    /**
     * public static方法
     */
    @Test
    public void test01() {
        method1(-10, x -> Math.abs(x));
        method1(-10, Math::abs);
    }

    /**
     * public方法
     */
    @Test
    public void test02() {
        Math math = new Math();
        method1(-10, x -> math.test1(x));
        method1(-10, math::test1);
        method2(-10, math::test2);
    }

    /**
     * constructor
     */
    @Test
    public void test03() {
        Math math1 = method3("math1", x -> new Math(x));
        System.out.println(math1);
        Math math2 = method3("math2", Math::new);
        System.out.println(math2);
    }

    public void method4(Math math, Integer num, IMath iMath) {
        System.out.println(iMath.test(math, num));
    }

    /**
     * 传递类名，不建议使用
     */
    @Test
    public void test04() {
        Math math = new Math();
        method4(math, -10, (m, x) -> math.test1(x));
        method4(new Math(), -10, Math::test1);
    }
}
